package com.study.util.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResult<T> {
    private boolean success;
    private Integer code;
    private String message;
    private T data;

    public ApiResult(){
    }

    public ApiResult(ResultCode resultCode) {
        this(resultCode, null);
    }

    public ApiResult(ResultCode resultCode, T data) {
        this.success = resultCode.isSuccess();
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
        this.data = data;

    }

    public static ApiResult SUCCESS() {
        return new ApiResult(CommonsResultCode.SUCCESS);
    }

    public static <T> ApiResult SUCCESS(T t) {
        return new ApiResult(CommonsResultCode.SUCCESS, t);
    }

    public static ApiResult FALL() {
        return new ApiResult(CommonsResultCode.FAIL);
    }

    public static ApiResult<?> FALL(String message) {
        ApiResult<?> responseResult = new ApiResult<>();
        responseResult.success = false;
        responseResult.code = -1;
        responseResult.message = message;
        return responseResult;
    }

}
